﻿@model cloudscribe.Core.Web.ViewModels.RoleAdmin.RoleViewModel
@inject ICoreThemeHelper themeHelper
@inject IStringLocalizer<CloudscribeCore> sr
@inject IOptions<SiteConfigOptions> setupOptionsAccessor
@{
    ViewData["BodyClass"] = "admin-section role-edit";
    var themeSettings = themeHelper.GetThemeSettings();
    if (themeSettings.AdminSideNavExpanded) { ViewData["SideNavToggle"] = "show"; }
    ViewData["SideNavVisible"] = true;
    var setupOptions = setupOptionsAccessor.Value;
}
<h2>@ViewData["Title"]</h2>
<form asp-controller="RoleAdmin" asp-action="RoleEdit" data-submit-once="true">
    <input asp-for="Id" type="hidden" />
    <input asp-for="SiteId" type="hidden" />
    <input asp-for="NormalizedRoleName" type="hidden" />
    <div asp-validation-summary="All" class="text-danger"></div>
    <div class="mb-3">
        <label class="form-label" asp-for="RoleName">@sr["Role Name"]</label>
        <input asp-for="RoleName" class="form-control" />
        <span asp-validation-for="RoleName" class="invalid-feedback"></span>
        @Html.ValidationMessage("roleerror", new { @class = "text-danger" })
    </div>
    <div class="mb-3">
        <button name="submit" type="submit" class="btn btn-primary" data-disabled-text='@sr["Working..."]' data-enabled-text='@sr["Save"]'>@sr["Save"]</button>
        @if (Model.IsDeletable(setupOptions.RolesThatCannotBeDeleted))
        {
            <button type="button" class="btn btn-danger " data-bs-toggle="modal" data-bs-target="#confirmDeleteModal">
                @sr["Delete"]
            </button>
        }

    </div>
</form>
<form class="form-inline" asp-controller="RoleAdmin" asp-action="RoleDelete">
    <input name="SiteId" value="@Model.SiteId" type="hidden" />
    <input id="roleId" name="roleId" type="hidden" value="@Model.Id" />
    <div class="modal fade" id="confirmDeleteModal" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteHeading">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="confirmDeleteHeading">@sr["Confirm Delete"]</h4>
                    <button type="button" data-bs-dismiss="modal" class="btn-close" aria-label='@sr["Close"]'></button>
                </div>
                <div class="modal-body">
                    @string.Format(sr["Are you sure you want to delete {0}?"], Model.RoleName)
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-bs-dismiss="modal">@sr["Cancel"]</button>
                    <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                </div>
            </div>
        </div>
    </div>

</form>

@section SideNav {
    @{ await Html.RenderPartialAsync("AdminSideNav"); }
}
@section Toolbar{
    @{ await Html.RenderPartialAsync("AdminSideNavToggle"); }
}
@section scripts {
    @{ await Html.RenderPartialAsync("AdminSideNavScripts"); }
    <script src="~/cr/js/jquery.validate.min.js"></script>
    <script src="~/cr/js/jquery.validate.unobtrusive.min.js"></script>
    <script src="~/cr/js/unobtrusive-validation-bs4.min.js"></script>
    <script src="~/cr/js/jquery.validate.hooks.min.js"></script>
    <script src="~/cr/js/jqueryvaildation.submitonce-unobtrusive.min.js"></script>
}
